package cxydmmszl.chapter09.t159;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * <li style="color: red;">Prob</li>
 * 并查集实现
 * <li style="color: green;">Desc</li>
 *
 * <li style="color: green;">Input</li>
 *
 * <li style="color: green;">Output</li>
 *
 * <li style="color: blue;">Link</li> CD66
 *
 * @author habitplus
 * @since 2021-10-13 21:07
 */
public class Main {
    static final StreamTokenizer st =
            new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int nextInt() {
        try {
            st.nextToken();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (int) st.nval;
    }

    public static void main(String[] sss) {
        int n = nextInt();
        int m = nextInt();

        UF uf = new UF(n);
        int opt, x, y;
        while (m-- > 0) {
            opt = nextInt();
            x = nextInt();
            y = nextInt();

            if (opt == 1) {
                boolean ans = uf.connect(x - 1, y - 1);
                System.out.println(ans ? "Yes" : "No");
            } else if (opt == 2) {
                uf.union(x - 1, y - 1);
            }
        }
    }
}

class UF {
    private final int[] parent;
    private int[] weight;
    private int count;

    public UF(int n) {
        this.count = n;
        this.parent = new int[n];
        this.weight = new int[n];
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
            weight[i] = 1;
        }
    }

    public int find(int x) {
        while (x != parent[x]) {
            x = parent[x];
        }
        return x;
    }

    public boolean connect(int x, int y) {
        return find(x) == find(y);
    }

    public void union(int x, int y) {
        int rx = find(x);
        int ry = find(y);
        // 已经是同一个集合了
        if (rx == ry) return;

        // 谁的权重大，谁是爹，相等则 ry 是爹
        if (weight[rx] > weight[ry]) {
            parent[ry] = rx;
            weight[rx] += weight[ry];
        } else {
            parent[rx] = ry;
            weight[ry] += weight[rx];
        }
        // 集合数减一
        count--;
    }

    public int count() {
        return count;
    }
}
